<template>
	<view class="comment">
		<u--textarea v-model="commentInfo.content" placeholder="请输入内容" count auto-height></u--textarea>
		<view class="btn_send">
			<u-button color="#cde6c7" text="发表" @click="sendComment()"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad(option) {
			this.commentInfo.uid=option.uid
			this.commentInfo.nid=option.nid
		},
		data() {
			return {
				commentInfo:{
					uid:'',
					nid:'',
					content:''
				},
				value: '统计字数',
			}
		},
		methods:{
			sendComment() {
				uni.request({
					url: 'http://localhost:8081/comment/addComment',
					method: 'POST',
					data: this.commentInfo,
					header: {
						'Content-Type': 'application/json',
					},
					dataType: 'json',
					success: (res) => {
						if (res.data.state == 200) {
							uni.showToast({
								title: '发表成功',
								duration: 1000,
							});
						} else {
							uni.$u.toast(res.data.message)
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.btn_send {
		width: 90%;
		margin: auto;
		position: fixed;
		bottom: 40rpx;
		left: 0;
		right: 0;
		z-index: 1;
	}
</style>
